package Shapes;

import processing.core.*;

/**
 * @author chen
 * @see could be delete later time, server as the boundary of the flows, 
 * I tried to draw a bezier line at the begining, but it seems there are some mistakes
 * when dealing with the three angle calculate
 * 
 */

public class Edge extends shape {

	public PVector ori = new PVector(50, 50);
	public PVector des = new PVector(30, 200);
	
	public int buffer = 20;
	
	public String name = "";
	
	/**
	 * Bezier.
	 * 
	 * The first two parameters for the bezier() function specify the first
	 * point in the curve and the last two parameters specify the last
	 * point. The middle parameters set the control points that define the
	 * shape of the curve.
	 */
	
	public Edge(PApplet p) {
		super(p);
		// TODO Auto-generated constructor stub
	}
	

	
	public void setup(float ori_x, float ori_y, float ori_z, float des_x, float des_y, float des_z) {
				
		this.ori.x = ori_x;
		this.ori.y = ori_y;
		this.ori.z = ori_z;
		this.des.x = des_x;
		this.des.y = des_y;
		this.des.z = des_z;

	}

	
	public void draw() {
		parent.smooth();
		PVector dir = des.get();
		dir.sub(ori);
		dir.normalize();

		PVector cro = dir.get();
		// cro.dot(new PVector(0,0,1));

		// cro.cross(new PVector(0,0,1));
		// cro.normalize();
		PVector t = cro.get();

		cro.x = t.y * 1 - 0;
		cro.y = t.x * 1 - 0;
		cro.z = 0;

		float dis = des.dist(ori);

		PVector ori1 = ori.get();
		cro.mult(buffer);
		ori1.add(cro);

		PVector ori2 = ori.get();
		ori2.sub(cro);

		PVector des1 = des.get();
		des1.add(cro);

		PVector des2 = des.get();
		des2.sub(cro);

		cro.normalize();
		cro.mult((float) (buffer/2.0));

		PVector c1 = ori.get();
		dir.mult((float) (dis * 0.3));
		c1.add(dir);

		PVector c11 = c1.get();
		c11.add(cro);

		PVector c12 = c1.get();
		c12.sub(cro);

		PVector c2 = c1.get();
		c2.add(dir);

		PVector c21 = c2.get();
		c21.add(cro);

		PVector c22 = c2.get();
		c22.sub(cro);

		parent.bezier(ori1.x, ori1.y, c11.x, c11.y, c21.x, c21.y, des1.x, des1.y);
		parent.bezier(ori2.x, ori2.y, c12.x, c12.y, c22.x, c22.y, des2.x, des2.y);

	}

}
